/*
 * @Author: xiaosihan 
 * @Date: 2023-12-18 01:56:28 
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2023-12-19 22:11:32
 */
import { BufferGeometry, Mesh, SphereGeometry, MeshBasicMaterial, Material } from "three";
import AreaName1 from "../AreaName1/AreaName1";

// 小球
export default class Ball extends Mesh {

    constructor(name: string) {
        super();

        this.lable.text = `${name}\n\n\n`;
        
        //three事件
        this.userData = {
            cursor: "pointer",
            enableEvent: true,
        };
        this.addEventListener("click", e => { });
        this.addEventListener("mouseenter", e => {
            this.lable.visible = true;
        });
        this.addEventListener("mouseleave", e => {
            this.lable.visible = this.active || false;
        });
    }

    // 小球网格模型
    static ballGeo = (() => {
        const ballGeo = new SphereGeometry(0.03, 100, 100);
        ballGeo.translate(0, 0.05, 0);
        return ballGeo;
    })();

    //红色材质
    material = new MeshBasicMaterial({ color: "#DFC52E" });

    geometry = Ball.ballGeo;

    // 标签
    lable = (() => {
        const lable = new AreaName1("", 16, "#fff");
        lable.position.set(0, 0.1, 0);
        lable.visible = false;
        this.add(lable);
        return lable;
    })();

    active = false;

    // 是否选中
    isActive(bool: boolean) {
        this.active = bool;
        this.lable.visible = bool;
        (this.material as MeshBasicMaterial).color.set(bool ? "#F86564" : "#DFC52E");
    }

}